create table "public"."feedback" (
    "id" bigint generated by default as identity not null,
    "created_at" timestamp with time zone default now(),
    "response_id" uuid not null,
    "feedback_metric_id" bigint not null,
    "boolean_value" boolean,
    "float_value" double precision,
    "string_value" text,
    "categorical_value" text,
    "created_by" text not null
);


alter table "public"."feedback" enable row level security;

create table "public"."feedback_metrics" (
    "id" bigint generated by default as identity not null,
    "created_at" timestamp with time zone not null default now(),
    "helicone_api_key_id" bigint not null,
    "name" text not null,
    "data_type" text not null
);


alter table "public"."feedback_metrics" enable row level security;

CREATE UNIQUE INDEX feedback_metrics_pkey ON public.feedback_metrics USING btree (id);

CREATE UNIQUE INDEX feedback_pkey ON public.feedback USING btree (id);

CREATE UNIQUE INDEX unique_helicone_api_key_metric ON public.feedback_metrics USING btree (helicone_api_key_id, name);

alter table "public"."feedback" add constraint "feedback_pkey" PRIMARY KEY using index "feedback_pkey";

alter table "public"."feedback_metrics" add constraint "feedback_metrics_pkey" PRIMARY KEY using index "feedback_metrics_pkey";

alter table "public"."feedback" add constraint "check_single_value" CHECK (((((((boolean_value IS NOT NULL))::integer + ((float_value IS NOT NULL))::integer) + ((categorical_value IS NOT NULL))::integer) + ((string_value IS NOT NULL))::integer) = 1)) not valid;

alter table "public"."feedback" validate constraint "check_single_value";

alter table "public"."feedback" add constraint "feedback_feedback_metric_id_fkey" FOREIGN KEY (feedback_metric_id) REFERENCES feedback_metrics(id) not valid;

alter table "public"."feedback" validate constraint "feedback_feedback_metric_id_fkey";

alter table "public"."feedback" add constraint "feedback_response_id_fkey" FOREIGN KEY (response_id) REFERENCES response(id) not valid;

alter table "public"."feedback" validate constraint "feedback_response_id_fkey";

alter table "public"."feedback_metrics" add constraint "feedback_metrics_helicone_api_key_id_fkey" FOREIGN KEY (helicone_api_key_id) REFERENCES helicone_api_keys(id) not valid;

alter table "public"."feedback_metrics" validate constraint "feedback_metrics_helicone_api_key_id_fkey";

alter table "public"."feedback_metrics" add constraint "unique_helicone_api_key_metric" UNIQUE using index "unique_helicone_api_key_metric";


